import matplotlib.pyplot as plt
import seaborn as sns


def drawFigure(train):
    # 该问题为分类问题，类别型特征直方图可用countplot
    plt.figure(1)
    sns.countplot(train['Target'])
    plt.xlabel('Diabetes')
    plt.ylabel('Number of occurrences')

    plt.figure(2)
    ### Number of occurrences
    sns.countplot(train['pregnants'])
    plt.xlabel('Number of pregnants')
    plt.ylabel('Number of occurrences')

    plt.figure(3)
    # 怀孕次数与糖尿病的关系
    sns.countplot(x="pregnants", hue="Target", data=train)

    plt.figure(4)
    # 血浆葡萄糖浓度与发病的关系
    sns.distplot(train.Plasma_glucose_concentration, kde=False)
    plt.xlabel('Plasma_glucose_concentration')
    plt.ylabel('Number of occurrences')

    plt.figure(5)
    sns.violinplot(x='Target', y='Plasma_glucose_concentration', data=train, hue="Target")
    plt.xlabel('Diabetes', fontsize=12)
    plt.ylabel('Plasma_glucose_concentration', fontsize=12)

    plt.figure(6)
    # 血压与糖尿病的关系
    sns.distplot(train.blood_pressure, kde=False)
    plt.xlabel('blood_pressure')
    plt.ylabel('frequency')

    plt.figure(7)
    sns.violinplot(x='Target', y='blood_pressure', data=train, hue="Target")
    plt.xlabel('Diabetes', fontsize=12)
    plt.ylabel('blood_pressure', fontsize=12)

    plt.figure(8)
    # 三头肌皮褶厚度（单位：mm）与糖尿病的关系
    sns.distplot(train.Triceps_skin_fold_thickness, kde=False)
    plt.xlabel('Triceps_skin_fold_thickness')
    plt.ylabel('frequency')

    plt.figure(9)
    sns.violinplot(x='Target', y='Triceps_skin_fold_thickness', data=train, hue="Target")
    plt.xlabel('Diabetes', fontsize=12)
    plt.ylabel('Triceps_skin_fold_thickness', fontsize=12)

    plt.figure(10)
    # 餐后血清胰岛素（单位:mm）
    sns.distplot(train.serum_insulin, kde=False)
    plt.xlabel('serum_insulin')
    plt.ylabel('frequency')

    plt.figure(11)
    sns.violinplot(x='Target', y='serum_insulin', data=train, hue="Target")
    plt.xlabel('Diabetes', fontsize=12)
    plt.ylabel('serum_insulin', fontsize=12)

    plt.figure(12)
    # 体重指数（体重（公斤）/ 身高（米）^2）
    sns.distplot(train.BMI, kde=False)
    plt.xlabel('BMI')
    plt.ylabel('frequency')

    plt.figure(13)
    sns.violinplot(x='Target', y='BMI', data=train, hue="Target")
    plt.xlabel('Diabetes', fontsize=12)
    plt.ylabel('BMI', fontsize=12)

    plt.figure(14)
    # 糖尿病家系作用
    sns.distplot(train.Diabetes_pedigree_function, kde=False)
    plt.xlabel('Diabetes_pedigree_function')
    plt.ylabel('frequency')

    plt.figure(15)
     # age
    sns.distplot(train.Age, kde=False)
    plt.xlabel('Age')
    plt.ylabel('frequency')

    DF1 = train.groupby(['Age', 'Target'])['Age'].count().unstack('Target').fillna(0)
    DF1[[0, 1]].plot(kind='bar', stacked=True)

    DF = train.groupby(['Diabetes_pedigree_function', 'Target'])['Diabetes_pedigree_function'].count().unstack('Target').fillna(0)
    DF[[0, 1]].plot(kind='bar', stacked=True)

    BMIDF = train.groupby(['BMI', 'Target'])['BMI'].count().unstack('Target').fillna(0)
    BMIDF[[0, 1]].plot(kind='bar', stacked=True)

    # 特征之间相关性
    data_corr = train.corr().abs()
    plt.subplots(figsize=(13, 9))
    sns.heatmap(data_corr, annot=True)

